﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace timetableasy.Models
{
    public class ClassRepository : UserRepository
    {
        private TimeTableDBDataContext db = new TimeTableDBDataContext();

        //Query Methods
        public IQueryable<Class> FindAllClasses()
        {
            return db.Classes;
        }

        public List<Class> GetAllClasses()
        {
            return db.Classes.ToList<Class>();
        }

        public List<String> GetAllClassesNames()
        {
            List<string> list = new List<string>();
            foreach (Class c in this.GetAllClasses())
            {
                list.Add(c.ClassName);
            }
            return list;
        }

        public Class GetClassById(int id)
        {
            return db.Classes.SingleOrDefault(c => c.ClassId == id);
        }

        public int GetClassIdByName(string name)
        {
            return db.Classes.SingleOrDefault(c => c.ClassName == name).ClassId;
        }

        //Insert/Delete Methods

        public void Add(Class aClass)
        {
            db.Classes.InsertOnSubmit(aClass);
        }

        public void Delete(Class aClass)
        {
            db.Classes.DeleteOnSubmit(aClass);
        }

        //Persistence

        public void Save()
        {
            db.SubmitChanges();
        }
    }
}